home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / ROM_Kernel_Manuals / Devices / dev_examples / V36_Device_Use.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-20  |  2.5 KB  |  81 lines

  1.   /*
  2.    * V36_Device_Use.c
  3.    *
  4.    * This is an example of using the serial device.
  5.    * First, we will attempt to create a message port with CreateMsgPort()
  6.    * Next, we will attempt to create the I/O request with CreateIORequest()
  7.    * Then, we will attempt to open the serial device with OpenDevice()
  8.    * If successful, we will send the SDCMD_QUERY command to it
  9.    * and reverse our steps.
  10.    * If we encounter an error at any time, we will gracefully exit.
  11.    *
  12.    * Compile with SAS C 5.10  lc -cfistq -v -y -L
  13.    *
  14.    * Requires Kickstart V36 or greater.
  15.    *
  16.    * Run from CLI only
  17.    */
  18.  
  19.   #include <exec/types.h>
  20.   #include <exec/memory.h>
  21.   #include <exec/io.h>
  22.   #include <devices/serial.h>
  23.  
  24.   #include <clib/exec_protos.h>
  25.   #include <clib/alib_protos.h>
  26.  
  27.   #include <stdio.h>
  28.  
  29.   #ifdef LATTICE
  30.   int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
  31.   int chkabort(void) { return(0); }  /* really */
  32.   #endif
  33.  
  34.   void main(void)
  35.   {
  36.   struct MsgPort *SerialMP;       /* pointer to our message port */
  37.   struct IOExtSer *SerialIO;      /* pointer to our I/O request */
  38.  
  39.       /* Create the message port */
  40.   if (SerialMP=CreateMsgPort())
  41.       {
  42.           /* Create the I/O request */
  43.       if (SerialIO = CreateIORequest(SerialMP,sizeof(struct IOExtSer)))
  44.           {
  45.               /* Open the serial device */
  46.           if (OpenDevice(SERIALNAME,0,(struct IORequest *)SerialIO,0L))
  47.  
  48.               /* Inform user that it could not be opened */
  49.               printf("Error: %s did not open\n",SERIALNAME);
  50.           else
  51.               {
  52.               /* device opened, send query command to it */
  53.               SerialIO->IOSer.io_Command  = SDCMD_QUERY;
  54.               if (DoIO((struct IORequest *)SerialIO))
  55.  
  56.                   /* Inform user that query failed */
  57.                   printf("Query  failed. Error - %d\n",SerialIO->IOSer.io_Error);
  58.               else
  59.                   /* Print serial device status - see include file for meaning */
  60.                   printf("\n\tSerial device status: %x\n\n",SerialIO->io_Status);
  61.  
  62.               /* Close the serial device */
  63.               CloseDevice((struct IORequest *)SerialIO);
  64.               }
  65.           /* Delete the I/O request */
  66.           DeleteIORequest(SerialIO);
  67.           }
  68.       else
  69.           /* Inform user that the I/O request could be created */
  70.           printf("Error: Could create I/O request\n");
  71.  
  72.       /* Delete the message port */
  73.       DeleteMsgPort(SerialMP);
  74.       }
  75.   else
  76.       /* Inform user that the message port could not be created */
  77.       printf("Error: Could not create message port\n");
  78.   }
  79.  
  80.  
  81.